﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tron
{
    class RepeatGameTypeScoreHelper
    {
        public List<int> TotalScores { get; private set; }
        public List<int> Wins { get; private set; }
        public List<int> Losses { get; private set; }
        public List<int> Ties { get; private set; }

        public RepeatGameTypeScoreHelper()
        {
            List<int> tempList = new List<int>(Constants.PlayerColors.Count);
            for (int i = 0; i < Constants.PlayerColors.Count; i++)
            {
                tempList.Add(0);
            }

            TotalScores = new List<int>(tempList);
            Wins = new List<int>(tempList);
            Losses = new List<int>(tempList);
            Ties = new List<int>(tempList);
        }

        public void Reset()
        {
            for (int i = 0; i < TotalScores.Count; i++)
            {
                TotalScores[i] = 0;
                Wins[i] = 0;
                Losses[i] = 0;
                Ties[i] = 0;
            }

        }

        public void AddScoresToTotals(List<int> scores)
        {
            for (int i = 0; i < scores.Count; i++)
            {
                TotalScores[i] += scores[i];
                if ( scores[i] == 1)
                {
                    Wins[i]++;
                }
                else if (scores[i] == -1) 
                {
                    Losses[i]++;
                }
                else 
                {
                    Ties[i]++;
                }
            }
        }

        public override string ToString()
        {
            String s = "";
            for(int i = 0; i < TotalScores.Count; i++)
            {
                int score = TotalScores[i];
                s += Constants.PlayerTypes[i].ToString() + " total score: " + TotalScores[i] + "("+Wins[i]+"/"+Losses[i]+"/"+Ties[i]+")\n";
            }
            return Constants.GetOptionsString() + s;
        }

        public string ToStringForFile()
        {
            String s = "name\tscore\twins\tlosses\tties\r\n";
            for (int i = 0; i < TotalScores.Count; i++)
            {
                int score = TotalScores[i];
                s += Constants.PlayerTypes[i].ToString() + "\t" + TotalScores[i] + "\t" +
                     Wins[i] + "\t" + Losses[i] + "\t" + Ties[i] + "\r\n";
            }
            return Constants.GetOptionsStringForFile() + "\r\n" + s;
        }
    }
}